/**
 * jQuery for module textbooks - controller course
 * 
 * @author	huytbt
 * @date	2012-06-02
 * @version	1.0
 */

;if(window.jQuery) (function($){
	if (!jQuery.h) jQuery.extend({h:{}}); // declare alias $.h
	if (!jQuery.h.textbooks) jQuery.h.textbooks = {}; // declare alias $.h.textbooks
	jQuery.h.textbooks.course = {
		/**
		 * Class FormAddCourse - used to process add course
		 */
		FormAddCourse: function(element)
		{
			var _this = this;
			_this.instance = $(element);
			
			_this.initForm = function(){
				_this.instance.find('.h-textbooks-select-department-id').change(function(){
					if ($(this).val()) {
						_this.instance.find('.h-textbooks-input-course-name').setOptions({extraParams:{department_id:$(this).val()}});
						_this.instance.find('.h-textbooks-input-course-name').removeAttr('disabled');
					} else
						_this.instance.find('.h-textbooks-input-course-name').attr('disabled', 'disabled');
				});
				
				return _this;
			};
			
			_this.init = function(){
				var val = _this.instance.find('.h-textbooks-select-department-id').val();
				if (val) {
					setTimeout(function(){
						_this.instance.find('.h-textbooks-input-course-name').setOptions({extraParams:{department_id:val}});
					}, 1000);
					_this.instance.find('.h-textbooks-input-course-name').removeAttr('disabled');
				} else
					_this.instance.find('.h-textbooks-input-course-name').attr('disabled', 'disabled');
			}
			
			_this.init();
		}
	};
})(jQuery);

;if(window.jQuery) (function($){
	$(document).ready(function(){
		$('form.h-textbooks-course-form-add-course').each(function(){
			var $addCourse = new jQuery.h.textbooks.course.FormAddCourse(this);
			$addCourse.initForm();
		});
		
	});
})(jQuery);